#ifndef HWFFMPEGFIND_H
#define HWFFMPEGFIND_H

extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavdevice/avdevice.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
#include <libavutil/mem.h>
#include <libavutil/fifo.h>
#include <libavutil/frame.h>
#include <libswscale/swscale.h>
#include <libavutil/pixdesc.h>
#include <libavutil/hwcontext.h>
#include <libavutil/opt.h>
#include <libavutil/avassert.h>
#include <libavutil/imgutils.h>
}

#include <QObject>
#include <QMutex>
#include <QImage>
#include <QDebug>
#include <QTime>

class HWFFmpegFind : public QObject
{
    Q_OBJECT
public:
    HWFFmpegFind(QObject *parent = nullptr);
    ~HWFFmpegFind();

    void setUrl(QString url);
    bool init();
    void play();
    void stopReadFrame();

signals:
    void drawImage(const QImage& frame);    /* 发送图像信号 */

private:
    AVFrame* alloc_picture(enum AVPixelFormat pix_fmt, qint32 width, qint32 height);

private:
    QString m_url;
    qint32 m_video_stream_index;
    qint32 m_video_width;
    qint32 m_video_height;
    bool m_is_stop;

    QMutex m_mutex;

    AVFormatContext *m_avformat_context;
    AVCodecContext *m_avcodec_context;
    AVFrame *m_av_frame_buffer;
    SwsContext *m_sws_context;
    AVPacket *m_av_packet;
    AVBufferRef *m_hw_device_context;
};


#endif // HWFFMPEGFIND_H
